package com.lzy.canal.register.consumer;

import com.alibaba.otter.canal.protocol.CanalEntry;
import com.lzy.canal.component.consumer.MysqlConsumer;

/**
 * 注册器管理
 *
 */
public class ConsumerRegisterManage {

    private final DdlConsumerRegister ddlConsumerRegister;

    private final DmlConsumerRegister dmlConsumerRegister;

    public ConsumerRegisterManage(DdlConsumerRegister ddlConsumerRegister, DmlConsumerRegister dmlConsumerRegister) {
        this.ddlConsumerRegister = ddlConsumerRegister;
        this.dmlConsumerRegister = dmlConsumerRegister;
    }


    /**
     * 获取注册器
     *
     * @param rowChage
     * @return
     */
    public ConsumerRegister getRegister(CanalEntry.RowChange rowChage) {
        if (rowChage.getIsDdl()) {
            return ddlConsumerRegister;
        }
        return dmlConsumerRegister;
    }

    /**
     * 获取消息处理器
     *
     * @param rowChange   记录
     * @param schemaName 库名
     * @param tableName  表名
     * @return
     */
    public MysqlConsumer getConsumerRegister(CanalEntry.RowChange rowChange, String schemaName, String tableName) {
        ConsumerRegister register = getRegister(rowChange);
        return register.getConsumer(schemaName, tableName);
    }


}
